package com.example.myDesignPatterns.行为型模式.责任链模式Responsibility.用责任链模式处理全局异常.handler;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;

@ControllerAdvice
public class GlobalExceptionHandler {
    private final ExceptionHandler exceptionHandlerChain;

    public GlobalExceptionHandler(ExceptionHandler exceptionHandlerChain) {
        this.exceptionHandlerChain = exceptionHandlerChain;
    }

    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    public ResponseEntity<Object> handleException(Exception exception) {
        return exceptionHandlerChain.handle(exception);
    }
}
